import os
import argparse


def remove(path, regxes):
    if os.path.isfile(path):
        for regx in regxes:
            if path.endswith(regx):
                os.remove(path)
    else:
        files = os.listdir(path)
        for file in files:
            sub_path = os.path.join(path, file)
            remove(sub_path, regxes)

def main(args):
    remove(args.path, args.regxes)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Delete some regx files.')
    parser.add_argument('-path', default='./', type=str, help='Source Directory.')
    parser.add_argument('-regxes', action='append', default=['.o', 'o.d', '.dump', '.verilog', '.bin', '.elf', '.hex', '.s.save', '.log', '.map', '.swp'], type=list, help='File Type.')
    args = parser.parse_args()

    main(args)